<?php

class Bizprofile_Widgets_Advertise_Widget extends Tomato_Widget
{
    protected function _prepareShow()
    {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $lang = $request->getParam('lang');
        $this->_view->assign('lang', $lang);
        $count = 4;

        /**
        * Get connection to database
        **/
        $conn = Tomato_Db_Connection::factory()->getMasterConnection();

        /**
        * Enterprise model access to data
        **/
        $enterpriseDao = Tomato_Model_Dao_Factory::getInstance()->setModule('enterprise')->getEnterpriseDao();
        $enterpriseDao->setDbConnection($conn);

        /**
         * Info models of enterprise access to data
        **/
        $infoDao = Tomato_Model_Dao_Factory::getInstance()->setModule('enterprise')->getInfoDao();
        $infoDao->setDbConnection($conn);
        $infoDao->setLang($lang);

        $enterprises = $enterpriseDao->getAdvertise($count);
        $this->_view->assign('enterprises', $enterprises);

        /**
         * Get about us follow enterprise
        **/
        $arrInfos = array();
        foreach($enterprises as $enterprise){
            $infos = $infoDao->getInfos($enterprise->id, 5);
            $arrInfos[$enterprise->id] = isset($infos[0])?$infos[0]:null;
        }
        $this->_view->assign('arrInfos', $arrInfos);
    }
    protected function _prepareConfig()
    {

    }
}
